set more off
clear
cd "D:\Projects\HeterogeneousExternalities\Data\"

*Collapse data to week-by-urbanization level averages

*Vehicle counts
use Daily_Data.dta,clear
collapse (mean) veh , by(week_date urban_13)
save temporary_veh.dta,replace
	
*Gasoline Prices
use Daily_Data.dta,clear
duplicates drop county_fe rgas week_date, force
		collapse (mean) rgas, by(urban_13 week_date)
save temporary_gas.dta,replace		
	
	use temporary_veh.dta,clear
	replace veh=veh/100
	twoway line veh week_date if urban_13==1,/*
	*/ lwidth(medthick) ytitle(Vehicle Counts (100's), margin(0 3.15 0 0))    xtitle(Date) ylabel(,nogrid) xlabel(,nogrid) ||/*
	*/  line veh week_date if urban_13==2,lwidth(medthick) ||   line veh week_date if urban_13==3,lwidth(medthick) ||   line veh week_date if urban_13==4 , /*
	*/ xline(2756 2808 2860 2912 2964, lstyle(p6)) ylabel(2(4)10) yscale(lstyle(none)) xscale(lstyle(none)) xtitle("") saving(veh,replace) lwidth(medthick) /*
	*/ pstyle(p4)  lpattern(-..*.-) scale(1.1)   legend(label(1 "Large Central Metro")/* 
	*/label(2 "Large Fringe Metro") label(3 "Medium Metro") label(4 "Small Metro") pos(12) cols(2)) xlabel(2756 "2013" 2808 "2014" 2860 "2015" 2912 "2016" 2964 "2017")
	
	
	use temporary_gas.dta,clear
	twoway line rgas week_date if urban_13==1, legend(off)/*
	*/ lwidth(medthick) ytitle(Gasoline Price ($'s))    xtitle(Date) ylabel(,nogrid) xlabel(,nogrid) ||/*
	*/  line rgas week_date if urban_13==2,lwidth(medthick) ||   line rgas week_date if urban_13==3,lwidth(medthick) ||   line rgas week_date if urban_13==4 , /*
	*/ xline(2756 2808 2860 2912 2964, lstyle(p6)) ylabel(1.5(1)4.5) yscale(lstyle(none)) xscale(lstyle(none)) xtitle("") saving(gas,replace) lwidth(medthick) pstyle(p4)   lpattern(-..*.-) scale(1.1) /*
	*/ xlabel(2756 "2013" 2808 "2014" 2860 "2015" 2912 "2016" 2964 "2017")
		

	grc1leg  veh.gph gas.gph , col(1) graphregion(color(white) margin(zero))  iscale(.75) ysize(12) xsize(5)  legendfrom(veh.gph) position(12)  span imargin(0 0 0 0) graphregion(margin(l=15 r=15))

*Erase temp files	
erase temporary_gas.dta 
erase temporary_veh.dta
erase gas.gph
erase veh.gph
